package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.aspect.LogRecord;
import com.woniuxy.dao.CarAccidentMapper;
import com.woniuxy.dto.CarAccidentDto;
import com.woniuxy.entity.CarAccident;
import com.woniuxy.service.CarAccidentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class CarAccidentServiceImpl implements CarAccidentService {

    @Autowired
    private CarAccidentMapper carAccidentMapper;
    /**
     * 分页查询
     * @param condition
     * @param pageNum   当前页
     * @param pageSize  每页大小
     */
    @Override
    public PageInfo<CarAccidentDto> findByPage(Map<String, Object> condition, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CarAccidentDto> list = carAccidentMapper.findAll(condition);
        return new PageInfo<>(list);
    }

    /**
     * 添加
     * @param carAccident
     */
    @LogRecord
    @Override
    public int save(CarAccident carAccident) {
        return carAccidentMapper.save(carAccident);
    }

    /**
     * 修改
     *
     * @param carAccident
     */
    @LogRecord
    @Override
    public int updateById(CarAccident carAccident) {
        return carAccidentMapper.updateById(carAccident);
    }

    /**
     * 删除
     *
     * @param id
     */
    @LogRecord
    @Override
    public int deleteById(Integer id) {
        return carAccidentMapper.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @LogRecord
    @Override
    public int deleteBatch(String[] ids) {
        return carAccidentMapper.deleteBatch(ids);
    }

    /**
     * 批量添加数据
     *
     * @param carAccidentList
     */
    @Override
    public int insertBatch(List<CarAccidentDto> carAccidentList) {
        return carAccidentMapper.insertBatch(carAccidentList);
    }

    /**
     * 导出所有数据Excel
     */
    @LogRecord
    @Override
    public List<CarAccidentDto> findAll() {
        return carAccidentMapper.findAll(null);
    }
}
